package com.neusoft.neuiotms.dcom.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.neusoft.bizcore.web.dto.result.PageResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultDTO;
import com.neusoft.bizcore.web.dto.result.ResultListDTO;
import com.neusoft.bizcore.web.support.Searchable;
import com.neusoft.neuiotms.dcom.dto.SchedulingRuleDTO;
import com.neusoft.neuiotms.dcom.service.SchedulingRuleService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "排班规则管理")
@RestController
@RequestMapping(value = "/api/w/schedulingrules")
public class SchedulingRuleController {

    @Autowired
    private SchedulingRuleService schedulingRuleService;

    @ApiOperation("查询所有排班规则")
    @GetMapping
    public ResultListDTO<SchedulingRuleDTO> index(final Searchable searchable) {
        return ResultListDTO.success(this.schedulingRuleService.index(searchable));
    }

    @ApiOperation("分页查询所有排班规则")
    @GetMapping("/p")
    public PageResultDTO<SchedulingRuleDTO> search(final Pageable pageable, final Searchable searchable) {
        return PageResultDTO.success(this.schedulingRuleService.search(pageable, searchable));
    }

    @ApiOperation("创建排班规则")
    @PostMapping("")
    public ResultDTO<SchedulingRuleDTO> create(@RequestBody final SchedulingRuleDTO dto) {
        return ResultDTO.success(this.schedulingRuleService.create(dto));
    }

    @ApiOperation(value = "制定规则")
    @PutMapping("/{id}")
    public ResultDTO<SchedulingRuleDTO> update(@PathVariable final Long id, @RequestBody final SchedulingRuleDTO dto) {
        return ResultDTO.success(this.schedulingRuleService.update(id, dto));
    }

    @ApiOperation("排班规则详情")
    @GetMapping("/{id}")
    public ResultDTO<SchedulingRuleDTO> details(@PathVariable final Long id) {
        return ResultDTO.success(this.schedulingRuleService.details(id));
    }

    @ApiOperation("删除排班规则")
    @DeleteMapping("/{id}")
    public ResultDTO<Void> delete(@PathVariable final Long id) {
        this.schedulingRuleService.delete(id);
        return ResultDTO.success();
    }
}
